Configuring Hardware Buttons
If you want to have some sort of interactive capbability with your cluster then there are a couple of ways to do it:
- Momentary buttons
- A rotary encoder
Momentary Buttons
Momentary buttons can be connected to the Pi using any valid GPIO pin that is not already in use. You can then configure the software to take an action whenever the button is pressed. Buttons are ‘debounced’ by the software to stop actions being taken more than once, and there is a time limit between presses of 0.5 seconds.
To configure a momentary button, edit the sdc.ini file and locate the [buttons] section. Each entry in this section represents the action a single button can take.
The actions are defined as:
<unique name>=<GPIO Pin Number>[.<trigger>],<action>
[buttons]
; any button without pu or pd defaults to pu (pullup)
; allo buttons are active low.
button1=16,nextpage ; move to the next page
button2=17,prevpage ; move to the previous page
button3=18,logstartstop ; start or stop data logging
button4=19,logmarker ; put a marker in the datalog
button5=20,page=10 ; jump directly to page 10
button6=21,nextcomposite ; cycle the currently selected composite page
shutdownbutton=22.pu,shutdown ; execute shutdown action, enable pullup. This is an active low.
; Must be pulled low to execute the action.
altshutdownbutton=23.pd,shutdown ; execute shutdown action, enable pulldown so open circuit will pull it
; low. Must be held high to prevent the action from occurring.
The pin numbers here are the GPIO pins. Not Raspberry Pi Hardware pins. So for example, GPIO21 is on hardware pin 40 of the header.
The GPIO pins you are using must not be being used for any other purpose. The SDC I/O hat reserves the following pins:
Serial RX GPIO15
Serial TX GPIO14
SPI MISO GPIO9
SPI MOSI GPIO10
SPI CLK GPIO11
SPI CE0 GPIO8
The SPI pins above are reserved by the canbus version of the hat.There is one exception to this: The SDC I/O Hat connects an opto-isolator to GPIO13 so that you can use it to trigger a controlled shutdown. It is therefore reserved but in order to activate shutdown control you must configure an input for it in the form of a button entry as below:
[buttons]
shutdown=13.PD,shutdownThe input side of the opto-isolator is connected to a screw terminal from which you should supply an ignition fed 12v signal. See the SDC I/O Hat instructions for further details.
GPIO13 (controlled shutdown)
Possible Button Actions.
Action | Purpose |
---|---|
nextpage | Move to the next page. Wraps around back to the first page (page zero) |
prevpage | Move to the previous page. Wraps around back to the last page |
nextcontrol | Move the on screen highlight to the next control in the sequence. See touch actions for further information on sequencing |
prevcontrol | Move the on screen highlight to the previous control in the sequence. Note that if no control is highlighted for both prevcontrol and nextcontrol, the first one in the sequence will be highlighted when the first button activation is executed. |
go | Executes the action as configured in the XML for the highlighted control |
logstartstop | Starts or stops data logging (toggle) |
logmarker | Places a marker in the datalog if it is running. Markers are highlighted by a red vertical line in MegaLogViewer. |
nextcomposite | Cycle through the set of composites in the currently selected group |
nextgroup | Cycle through the composite groups on the page in order to be able to change the selected composite of one particular group. |
page= | Jump directly to a specific page number. |
shutdown | Shut down the software. Close all open files and save any important settings |
A momentary button input can of course be controlled by things other than buttons. You could trigger an action from another microcontroller for example, or in the case of the shutdown action the SDC I/O Hat has an input which is connected to GPIO13 via an opto-isolator. This is used as an ignition sense function which enables the Pi to be shut down properly before the ignition turns off. This makes it possible for settings to be saved between engine starts, such as the last page used. Also it enables the data log file to be closed properly. See the Controlled Shutdown for further details.
Note that there are other actions that could be specified here, as it’s the same set of actions as those used for ‘touch actions’ (the action to take when a button is pressed) but logically some are not useful when used in the context of a button. Similarly, you wouldn’t configure an actual touch screen action to move the highlight back and forth.